#ifndef _DOUBLEMATRIX_H_
#define _DOUBLEMATRIX_H_

#include <cmath>

class doublematrix
{
private:
	int m_iHeight, m_iWidth;
	double** p; 
	void delete_all() {
		for (int i = 0; i < m_iHeight; i++) 
			delete[] p[i];
		delete[] p;
	}
public:
	doublematrix() 
	{
		m_iHeight = 1, m_iWidth = 1;
		p = new double*[m_iHeight];
		for(int i = 0; i < m_iHeight; i++)
			p[i] = new double[m_iWidth];
		p[0][0]=1.0; 
	};
	doublematrix(int i, int j) 
	{
		m_iHeight = i, m_iWidth = j;
		p = new double*[m_iHeight];
		for(i = 0; i < m_iHeight; i++)
			p[i] = new double[m_iWidth];
	};
	doublematrix(doublematrix& b) {
		m_iHeight = b.m_iHeight;
		m_iWidth = b.m_iWidth;
		p = new double*[m_iHeight];
		for (int i = 0; i < m_iHeight; i++) {
			p[i] = new double[m_iWidth];
			for (int j = 0; j < m_iWidth; j++) {
				p[i][j] = b[i][j];
			}
		}
	}
	~doublematrix() {
		delete_all();
	}
	double* operator[](int i) { return p[i]; };
	double& get( int i, int j ) const { return p[i][j]; }
	int getRow() const { return m_iHeight; }
	int getCol() const { return m_iWidth; }
	void init(int i, int j) 
	{
		delete_all();
		m_iHeight = i, m_iWidth = j;
		p = new double*[m_iHeight];
		for(i = 0; i < m_iHeight; i++)
			p[i] = new double[m_iWidth];
	};
	void zero()
	{
		for (int i = 0; i < m_iHeight; i++) 
			for (int j = 0; j < m_iWidth; j++) 
				p[i][j] = 0.0;
	}
};



#endif	//_DOUBLEMATRIX_H_